package kin.context.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import kin.bean.security.Acl;
import kin.bean.security.Module;

public class SessionContext {
	private static final Map<String, HttpSession> ctx = new HashMap<String, HttpSession>();

	private static final Map<String, List<Module>> modules = new HashMap<String, List<Module>>();

	private static final Map<String, List<Acl>> acls = new HashMap<String, List<Acl>>();

	public static void addSessoin(HttpSession session, List<Module> list) {
		ctx.put(session.getId(), session);
		modules.put(session.getId(), list);
	}

	public static void addSessoin(HttpSession session, List<Module> list,List<Acl> aclss) {
		ctx.put(session.getId(), session);
		modules.put(session.getId(), list);
		acls.put(session.getId(), aclss);
	}
	
	public static void removeAcl(HttpSession session, List<Acl> aclss) {
		List<Acl> evryAcls = getAcl(session.getId());
		if (evryAcls.containsAll(aclss)) {
			evryAcls.removeAll(aclss);
			acls.put(session.getId(),evryAcls);
		}
	}

	public static void removeModule(HttpSession session) {
		// ctx.remove(session.getId());
		modules.remove(session.getId());
	}

	public static void removeSession(HttpSession session) {
		ctx.remove(session.getId());
		modules.remove(session.getId());
		acls.remove(session.getId());
	}

	public static HttpSession getSession(String sessionId) {
		return ((HttpSession) ctx.get(sessionId));
	}

	public static List<Module> getModule(String sessionId) {
		return modules.get(sessionId);
	}

	public static List<Acl> getAcl(String sessionId) {
		return acls.get(sessionId);
	}
}
